package ch05.service.impl;

import ch05.dao.UserDao;
import ch05.dao.impl.UserDaoImpl;
import ch05.factory.UserDaoFactory;
import ch05.pojo.User;
import ch05.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("userService")
public class UserServiceImpl implements UserService {
    //通过工厂获取所依赖的USerDao对象
//    private UserDao dao= UserDaoFactory.getInstance();
    /**
     * 声明接口类型的引用，和具体实现类解耦合
     */
    @Resource(type = UserDaoImpl.class)
    private UserDao userDao;

    /**
     * 保存用户信息
     * @param user
     */
    public void save(User user){
        //调用UserDao的方法保存用户信息
//        dao.save(user);
        userDao.save(user);
    }



    /**
     * dao属性的setter访问器，会被Spring调用，实现设值注入
     * @param userDao
     */
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
}
